﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using Microsoft.Practices.Unity;
using System.Configuration;
using Microsoft.Practices.Unity.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.ServiceModel.Web; 
namespace SkynetWindowService
{
    class Program
    {
        static void Main(string[] args)
        {

            var container = new UnityContainer();


            

            
            var AspectMap = new ExeConfigurationFileMap() { ExeConfigFilename = "./Config/Aspect.config" };
            var AspectSection = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(AspectMap, ConfigurationUserLevel.None).GetSection("unity") as UnityConfigurationSection;
            container.LoadConfiguration(AspectSection);

            
            var DataAccessMap = new ExeConfigurationFileMap() { ExeConfigFilename = "./Config/DataAccess.config" };
            var DataAccessSection = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(DataAccessMap, ConfigurationUserLevel.None).GetSection("unity") as UnityConfigurationSection;
            container.LoadConfiguration(DataAccessSection);
                        
            var BusinessMap = new ExeConfigurationFileMap() { ExeConfigFilename = "./Config/Business.config" };
            var BusinessSection = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(BusinessMap, ConfigurationUserLevel.None).GetSection("unity") as UnityConfigurationSection;
            container.LoadConfiguration(BusinessSection);


            

            var db = container.Resolve<Database>();

            var host = new Infrastructure.Aspect.Extensions.UnityServiceHost(typeof(global::Skynet.ServiceImplementation.SkynetLibraryService)) ;
            host.Container = container;

            var BCExamsHost = new Infrastructure.Aspect.Extensions.UnityServiceHost(typeof(global::Skynet.BusinessLogic.BusinessComponents.BCExams));
            BCExamsHost.Container = container;
            try
            {
                BCExamsHost.Open();

                Console.ReadLine();
            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                if ( BCExamsHost != null)
                    BCExamsHost.Close(); 
            }          
            


            //var hostSecurity = new Infrastructure.Aspect.Extensions.UnityServiceHost(typeof(global::Skynet.ServiceImplementation.SkynetSecurityTest));
            //hostSecurity.Container = container;  

            //var hostDual = new Infrastructure.Aspect.Extensions.UnityServiceHost(typeof(global::Skynet.ServiceImplementation.SkynetNotifierService));
            //hostDual.Container = container; 
            //var hostBCExam = new Infrastructure.Aspect.Extensions.UnityServiceHost(typeof(global::Skynet.BusinessLogic.BusinessComponents.BCExams)) ;
            //hostBCExam.Container = container; 
            //host.Open();
            //hostDual.Open();
            //hostBCExam.Open();
            ////hostSecurity.Open(); 
            //Console.WriteLine("servicio operativo"); 

            //Console.ReadLine();
            //hostSecurity.Close();
            //hostBCExam.Close();
            //hostDual.Close();
            //host.Close();

        }
    }
}

